/*
 * @Author: szx
 * @Date: 2021-12-01 13:41:03
 * @LastEditTime: 2021-12-01 13:43:19
 * @Description:
 * @FilePath: \leetcode\200-299\209\209.js
 */
/**
 * @param {number} target
 * @param {number[]} nums
 * @return {number}
 */
var minSubArrayLen = function (target, nums) {
    let l = 0,
        n = nums.length;
    let sum = 0;
    let cnt = Infinity;
    for (let i = 0; i < n; i++) {
        sum += nums[i];
        while (sum >= target) {
            if (cnt > i - l + 1) {
                cnt = i - l + 1;
            }
            sum -= nums[l];
            l++;
        }
    }
    if (cnt == Infinity) return 0;
    return cnt;
};
